package sk.avicularia.common;

import antlr.StringUtils;

public class Args
{
	/**
	 * Stringova reprezentacia obsahu pola
	 */
	private String str;
	
	/**
	 * Pole obsahujuce dvojice nazov hodnota
	 */
	private Object[] args;
	
	/**
	 * Vytvory nove pary dvojic nazov=hodnota ktore budu prevedene na string
	 */
	public Args(Object... args)
	{
		this.args = args;
		if (this.args == null)
		{
			throw new IllegalArgumentException("Missing arguments");
		}
		
		if (args.length % 2 != 0)
		{
			throw new IllegalArgumentException("Length of input variables has to be even.");
		}
	}
	
	/**
	 * Prevedie pary na retazec nazov=hodnota
	 */
	@Override
	public String toString()
	{
		if (this.str.length() == 0)
		{
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			for (int i = 0; i < args.length; i += 2)
			{
				sb.append(String.valueOf(args[i])).append("=").append(String.valueOf(args[i + 1]));
				if (i < args.length - 2)
				{
					sb.append(", ");
				}
			}
			sb.append("]");
			this.str = sb.toString();			
		}
		
		return str;
	}
}
